package main

import (
	"fmt"
	"reflect"
	"strings"
)

func main() {
	var x = "Hello World"
	y := "I love my country."

	fmt.Println(x)
	fmt.Println(reflect.TypeOf(x))

	fmt.Println(len(y))

	// 打印ASCII码
	fmt.Println("字母'A' AscII码 的值是：", "A"[0])

	// 字符串方法
	fmt.Println(strings.ToTitle(y)) // strings.Title()方法弃用
	fmt.Println(strings.ToLower(y))
	fmt.Println(strings.ToUpper(y))
	fmt.Println(strings.Replace(y, "love", "hate", -1))
	fmt.Println(strings.Contains(y, "love"))
	fmt.Println(strings.Repeat(y, 3))
	var arr []string = strings.Split(y, " ")
	for i, v := range arr {
		fmt.Println("Index: ", i, "value: ", v)
	}
	fmt.Printf("%q\n", arr)
	fmt.Println(arr[0])

	// 字符串分割
	z := strings.Split(y, " ")
	fmt.Println(z)
	fmt.Printf("The type of z is %s", reflect.TypeOf(z))
	fmt.Printf("The second element of z is %s \n", z[1])

	str := "New "
	fmt.Println(strings.Repeat(str, 4))
}
